/*
 * status.h
 *
 *  Created on: Mar 31, 2012
 *      Author: lin
 */

#ifndef STATUS_H_
#define STATUS_H_

#include <stdint.h>

typedef enum status_code {
    cOK = 0,
    cNotFound = 1,
    cCorruption = 2,
    cUnSupported = 3,
    cInvalArg = 4,
    cIOErr = 5
} status_code;

#define MAX_STATUS_MSG_LEN 56

typedef struct status {
    status_code code;
    char msg[MAX_STATUS_MSG_LEN];
} status;

extern const status s_ok;

void status_init(status *s, status_code code, const char *msg1,
        const char *msg2);

static inline status status_ok(void) {
    return s_ok;
}

static inline status status_notfount(const char *msg1, const char *msg2) {
    status s;
    status_init(&s, cNotFound, msg1, msg2);
    return s;
}

static inline status status_corruption(const char *msg1, const char *msg2) {
    status s;
    status_init(&s, cCorruption, msg1, msg2);
    return s;
}

static inline status status_unsupported(const char *msg1, const char *msg2) {
    status s;
    status_init(&s, cUnSupported, msg1, msg2);
    return s;
}

static inline status status_invalarg(const char *msg1, const char *msg2) {
    status s;
    status_init(&s, cInvalArg, msg1, msg2);
    return s;
}

static inline status status_ioerr(const char *msg1, const char *msg2) {
    status s;
    status_init(&s, cIOErr, msg1, msg2);
    return s;
}

#endif /* STATUS_H_ */
